package com.suning.utils;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * 〈一句话功能简述〉<br>
 * 〈功能详细描述〉
 *
 * @author 16080951(林健)
 * @Copyright (c) 2016 苏宁软件技术有限公司 版权所有
 * @see [相关类/方法]（可选）
 * @since [产品/模块版本] （可选）
 */
public class ThreadPool {

    private static ThreadPoolExecutor threadPoolExecutor = null;
    //池中所保存的线程数，包括空闲线程。
    private static int corePoolSize = 5;
    //池中所允许的最多线程数。
    private static int maximumPoolSize = 5;
    //当线程数大于核心时，此为终止前多余的空闲线程等待新任务的最长时间
    private static long keepAliveTime = 1000 * 60 * 5;


    public static void execute(Runnable runnable){
        if(threadPoolExecutor == null){
            threadPoolExecutor = new ThreadPoolExecutor(corePoolSize, maximumPoolSize, keepAliveTime,TimeUnit.MILLISECONDS,new LinkedBlockingQueue<Runnable>());
        }

        threadPoolExecutor.execute(runnable);
    }
}
